package com.xinqi.modules.course.content.controller.app;

import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.Param;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.course.clazz.dto.rsp.ClassAllResultDTO;
import com.xinqi.modules.course.content.domain.CourseContentEntity;
import com.xinqi.modules.course.content.dto.req.ContentMonthDayQueryDTO;
import com.xinqi.modules.course.content.service.CourseContentService;
import com.xinqi.modules.course.content.dto.req.CourseContentListDTO;
import com.xinqi.modules.course.content.dto.req.CourseContentQueryDTO;
import com.xinqi.modules.course.content.dto.req.CourseContentUpdateDTO;
import com.xinqi.modules.course.content.dto.rsp.CourseContentResultDTO;
import com.xinqi.modules.course.content.dto.rsp.CourseRepeatContentResult;
import com.xinqi.modules.stats.assistant.dto.req.AssistantTotalCheckDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 课程栏目汇总APP接口
 *
 * @author: dzy
 * @date: 2023/03/08
 */
@Tag(name = "App-课程栏目汇总记录", description = "课程栏目汇总记录")
@RestController
@RequestMapping("/app/course-content")
@RequiredArgsConstructor
public class CourseContentAppController {

    private final CourseContentService courseContentService;

    /**
     * 课程栏目汇总根据章节ID查询-分页
     *
     * @Description 传入章节ID
     * @Author dzy
     * @Date 10:10 2023/3/9 0009
     * @Return
     */
    @GetMapping("/chapter/page")
    public R<PageInfo<CourseContentResultDTO>> pageChapter(Param pageable, CourseContentQueryDTO dto) {
        List<String> orderList = new ArrayList<>();
        orderList.add("sort,desc");
        orderList.add("release_time,desc");
        pageable.setSorts(orderList);
        PageInfo<CourseContentResultDTO> page = courseContentService.page(pageable, dto);
        return R.ok(page);
    }

    /**
     * 课程章节ID查询查询列表
     *
     * @Description 传入章节ID
     * @Author 星星
     * @Date 10:10 2023/3/28
     * @Return
     */
    @GetMapping("/chapter/{chapterId}")
    public R getCourseContentByChapterId(@PathVariable("chapterId") Long chapterId) {
        if (chapterId == 0) {
            return R.ok();
        }
        List<CourseContentEntity> resultList = courseContentService.getCourseContentByChapterId(chapterId);
        return R.ok(resultList);
    }

    /**
     * 全部接口-查询年月数据
     *
     * @Description 传入班级id
     * @Author liu
     * @Date 10:10 2023/3/9 0009
     * @Return
     */
    @GetMapping("/selectYearMonth/{classId}")
    public R selectYearMonth(Param pageable, @PathVariable("classId") Long classId) {
        PageInfo<Map<String, Object>> res = courseContentService.selectYearMonth(pageable, classId);
        return R.ok(res);
    }

    /**
     * 全部接口-查询月日数据
     *
     * @Description 传入班级id, 年，月
     * @Author liu
     * @Date 10:10 2023/3/9 0009
     * @Return
     */
    @GetMapping("/selectMonthDay")
    public R selectMonthDay(ContentMonthDayQueryDTO queryParam) {
        List<Map<String, Object>> res = courseContentService.selectMonthDay(queryParam);
        return R.ok(res);
    }

    /**
     * 全部接口-查询年月日周数据
     *
     * @Description 传入班级id
     * @Author liu
     * @Date 10:10 2023/3/9 0009
     * @Return
     */
    @GetMapping("/selectYearMonthDay/{classId}")
    public R selectYearMonthDay(Param pageable, @PathVariable("classId") Long classId) {
        PageInfo<Map<String, Object>> res = courseContentService.selectYearMonthDay(pageable, classId);
        return R.ok(res);
    }

    /**
     * 全部接口-查询当天所有数据
     *
     * @Description 传入班级id, 年，月,日
     * @Author liu
     * @Date 10:10 2023/3/9 0009
     * @Return
     */
    @GetMapping("/selectAllDay")
    public R<List<CourseRepeatContentResult>> selectAllDay(@Validated ContentMonthDayQueryDTO queryParam) {
        List<CourseRepeatContentResult> res = courseContentService.selectAllDay(queryParam);
        return R.ok(res);
    }

    /**
     * 修改课程栏目作业信息
     *
     * @Author dzy
     * @Date 10:10 2023/3/9 0009
     * @Return
     */
    @Operation(summary = "修改 课程栏目汇总记录")
    @PutMapping("/{id}")
    public R update(@PathVariable("id") Long id, @Validated @RequestBody CourseContentUpdateDTO dto) {
        dto.setId(id);
        return courseContentService.updateById(dto);
    }

    /**
     * 移动到章节 课程栏目
     *
     * @Author dzy
     * @Date 10:10 2023/3/9 0009
     * @Return
     */
    @PutMapping("/shift-in")
    public R shiftIn(@RequestBody CourseContentListDTO dto) {
        return courseContentService.shiftIn(dto.getList());
    }

    /**
     * 移出章节 课程栏目
     *
     * @Author dzy
     * @Date 10:10 2023/3/9 0009
     * @Return
     */
    @PutMapping("/shift-out")
    public R shiftOut(@RequestBody CourseContentListDTO dto) {
        return courseContentService.shiftOut(dto.getList());
    }

}
